<?php
include_once 'RegistrationPresenter.php';
include_once 'AbstractView.php';
include_once 'InsultBuilder.php';
class RegistrationView extends AbstractView {
	private $presenter;
	public function __construct() {
		parent::__construct ();
		$this->presenter = new RegistrationPresenter ( $this, parent::getUserRepository () );
	}
	public function render() {
		if (isset ( $_POST ["userName"] )) {
			$user = new User ( trim ( $_POST ["userName"] ) );
			$user->setEmail ( trim ( $_POST ["email"] ) );
			$user->setPrivileges ( USER::USER_PRIVILEGES );
			$user->setName ( trim ( $_POST ["name"] ) );
			$this->presenter->register ( $user, trim ( $_POST ["password"] ), trim ( $_POST ["passwordConfirm"] ) );
			return;
		}
		
		require 'registration_form.phtml';
	}
	public function registrationSucceed() {
		$builder = new InsultBuilder ();
		$builder->setMessage ( "ראַסיאַללי ריכטיק וועב אַפּלאַקיישאַן וועלקאַמז איר,% נאמען%" )->setTitle ( "We meet again, old friend!" )->setPicture ( "registration_succeed.jpg" )->setSource ( "index.php" );
		parent::redirect ( $builder->build () );
	}
	public function registrationError($reason) {
		$builder = new InsultBuilder ();
		$builder->setMessage ( $reason )->setTitle ( "Wrong move buddy!" )->setPicture ( "registration_failed.jpg" )->setSource ( "registration.php" );
		parent::redirect ( $builder->build () );
	}
}

$view = new RegistrationView ();
$view->render ();

?>